#include<stdio.h>
#include<unistd.h>
#include<pthread.h>
struct data{
    int i_;
};

void* pthread_start(void* arg){
    struct data* lp=(struct data*)arg;
    while(1){
  //  printf("i am work pthread:%p\n",pthread_self());
    printf("i am work pthread:%d\n",lp->i_);
    sleep(1);
   // pthread_exit(NULL);
    pthread_cancel(pthread_self());
    }
    delete lp;
}
int main(){
    int i=0;
    for(i;i<4;i++){    
     struct data* lp=new struct data;
    lp->i_=i;

    pthread_t tid;
   int ret=  pthread_create(&tid,NULL,pthread_start,(void*)lp);
   if(ret<0){
       perror("pthread_create");
       return 0;
   }
    }
   while(1){
   printf("i am main pthread\n");
   sleep(2);
   }
    return 0;
}
